1
2
3
4
5
6
7 package ca.uhn.cache.internal.impl;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 import junit.framework.TestCase;
13 import junitx.framework.ArrayAssert;
14 import ca.uhn.cache.IDimension;
15 import ca.uhn.cache.IQueryParam;
16 import ca.uhn.cache.impl.Dimension;
17 import ca.uhn.cache.impl.StringParam;
18 import ca.uhn.cache.internal.IParamSpaceConfig;
19
20 /***
21 * Test cases for ParamSpaceConfig.
22 *
23 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
24 * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:21 $ by $Author: bryan_tripp $
25 */
26 public class ParamSpaceConfigTest extends TestCase {
27
28
29 static {
30 ClassLoader.getSystemClassLoader().setPackageAssertionStatus( "ca.uhn.cache", true );
31 }
32
33 /***
34 * @throws Exception ...
35 */
36 public void testGood() throws Exception {
37 IDimension one = new Dimension("one", new Class[] {StringParam.class});
38 IDimension two = new Dimension("two", new Class[] {StringParam.class});
39
40 List chunkBoundaries = new ArrayList();
41 chunkBoundaries.add( new StringParam(one, "c1") );
42 chunkBoundaries.add( new StringParam(one, "c2") );
43 chunkBoundaries.add( new StringParam(one, "c3") );
44
45 List saturationPoints = new ArrayList();
46 saturationPoints.add( new StringParam(one, "sp") );
47
48 IParamSpaceConfig config
49 = new ParamSpaceConfig(
50 new IDimension[] {one, two},
51 (IQueryParam[]) chunkBoundaries.toArray( new IQueryParam[] {} ),
52 (IQueryParam[]) saturationPoints.toArray( new IQueryParam[] {} ) );
53
54 assertEquals(2, config.getDimensions().length);
55 ArrayAssert.assertEquals( new IQueryParam[] {}, config.getChunkBoundaries(two));
56 assertEquals(false, config.isChunked(two));
57 assertEquals(3, config.getChunkBoundaries(one).length);
58 assertEquals(StringParam.class, config.getSaturationPoint(one).getClass());
59 }
60
61 /***
62 * @throws Exception ...
63 */
64 public void testBad() throws Exception {
65 IDimension one = new Dimension("one", new Class[] {StringParam.class});
66 IDimension two = new Dimension("two", new Class[] {StringParam.class});
67
68 IQueryParam chunkOne = new StringParam(one, "c1");
69 IQueryParam chunkTwo = new StringParam(one, "c2");
70 IQueryParam chunkThree = new StringParam(one, "c3");
71
72 List chunkBoundaries = new ArrayList();
73 chunkBoundaries.add( chunkOne );
74 chunkBoundaries.add( chunkTwo );
75 chunkBoundaries.add( chunkThree );
76
77 List satPoints = new ArrayList();
78
79 try {
80 IParamSpaceConfig config =
81 new ParamSpaceConfig(
82 new IDimension[] {two},
83 (IQueryParam[]) chunkBoundaries.toArray( new IQueryParam[] {} ),
84 (IQueryParam[]) satPoints.toArray( new IQueryParam[] {} ) );
85
86 fail( "Should have thrown exception due to unrecognized dimension in boundary map" );
87
88 } catch (AssertionError e) {
89
90 }
91
92 IParamSpaceConfig config
93 = new ParamSpaceConfig(
94 new IDimension[] {one},
95 (IQueryParam[]) chunkBoundaries.toArray( new IQueryParam[] {} ),
96 (IQueryParam[]) satPoints.toArray( new IQueryParam[] {} ) );
97
98 try {
99 config.isChunked(two);
100 fail("Should have thrown exception due to unrecognized dimension" );
101 } catch (AssertionError e) {
102
103 }
104
105 try {
106 config.getChunkBoundaries(two);
107 fail( "Should have thrown exception due to unrecognized dimension" );
108 } catch (AssertionError e) {
109
110 }
111
112 }
113
114 }